package dbInit

import (
	_ "github.com/go-sql-driver/mysql"
	"github.com/jinzhu/gorm"
	"gowork/recruit/model"
)

//var X *xorm.Engine
//
//func init(){
//	var xErr error
//	X, xErr = xorm.NewEngine("mysql", "root:new_password@tcp(127.0.0.1:3306)/recruit_xorm?charset=utf8")
//	if xErr != nil {
//		log.Fatal("数据库连接失败:", xErr)
//	}
//	if err := X.Sync2(new(model.JobSeekers), new(model.Position), new(model.JobSeekersPosition), new(model.Message)); err != nil {
//		log.Fatal("数据表同步失败:", err)
//	}
//}


var Db *gorm.DB

func init(){
	var err error
	Db, err = gorm.Open("mysql", "root:new_password@tcp(localhost:3306)/recruit_gorm?charset=utf8&parseTime=true")
	if err != nil {
		panic("failed to connect database")
	}
	Db.AutoMigrate(&model.JobSeekers{}, &model.Position{}, &model.JobSeekersPosition{}, &model.Message{})
}